from 读取文件 import *
from Curve_fitting import *
import numpy as np
import matplotlib.pyplot as plt


def Jkx_std(Y, n=6):  # 理论渐开线中, x与y的关系
    t = np.linspace(0, 1.06, 1000)
    r = 50
    w = 1
    x = r * (np.cos(w * t + 1.082) + w * t * np.sin(w * t + 1.082))
    x = x - x[0]
    y = r * (np.sin(w * t + 1.082) - w * t * np.cos(w * t + 1.082))
    y = y - y[0]
    re1 = CF(y, x, n=n)["Factor"]
    return np.polyval(re1, Y)


filename = "正向仿真数据/9v007.txt"
filename = np.array(loadDatadet(filename))
x_0 = 0
y_0 = 0

# print(filename)
x = filename[:, 0] + x_0
y = filename[:, 1] + y_0  # 平移到以原点为中心
# print(x)
# k = len(x)
# x_real = []  # 表示筛选的点
# y_real = []
# fig = plt.figure(figsize=(10, 10))
ax = plt.gca()
plt.scatter(x, y, s=0.1)
# for date in np.arange(0, k - 1, 1):
#     if 0.2 <= y[date] <= 24:
#         if x[date] <= Jkx_std(y[date]):
#             x_real.append(x[date])
#             y_real.append(y[date])
#             pass
#     pass
#
# plt.scatter(x_real, y_real, s=0.2)
# Cf = CF(y_real, x_real, n=6)
# s = np.linspace(0, 24, 100)
#plt.plot(np.polyval(Cf["Factor"], s), s, color='red')
# plt.xlim(-15, 15)
# plt.ylim(0, 30)
ax.grid()
para = np.linspace(1.08, 0, 1000)
r = 50
X = r * (np.cos(para + 1.082) + para * np.sin(para + 1.082))
Y = r * (np.sin(para + 1.082) - para * np.cos(para + 1.082))


plt.xlim(-15, 15)
plt.ylim(-30, 0)
ax.grid()
plt.scatter(X-X[0], Y-Y[0], 0.1)
# plt.rcParams['saving.dpi'] = 1000  # 图片像素
# plt.rcParams['figure.dpi'] = 1000

# plt.scatter(x, y)
plt.rcParams['savefig.dpi'] = 1000  # 图片像素
plt.rcParams['figure.dpi'] = 1000
plt.show()
